package com.easy.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.easy.entity.enums.PageSize;
import com.easy.entity.query.EmpQuery;
import com.easy.entity.po.Emp;
import com.easy.entity.vo.PaginationResultVO;
import com.easy.entity.query.SimplePage;
import com.easy.mappers.EmpMapper;
import com.easy.service.EmpService;
import com.easy.utils.StringTools;


/**
 * 员工表 业务接口实现
 */
@Service("empService")
public class EmpServiceImpl implements EmpService {

	@Resource
	private EmpMapper<Emp, EmpQuery> empMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<Emp> findListByParam(EmpQuery param) {
		return this.empMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(EmpQuery param) {
		return this.empMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<Emp> findListByPage(EmpQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<Emp> list = this.findListByParam(param);
		PaginationResultVO<Emp> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(Emp bean) {
		return this.empMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<Emp> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.empMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<Emp> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.empMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(Emp bean, EmpQuery param) {
		StringTools.checkParam(param);
		return this.empMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(EmpQuery param) {
		StringTools.checkParam(param);
		return this.empMapper.deleteByParam(param);
	}

	/**
	 * 根据Id获取对象
	 */
	@Override
	public Emp getEmpById(Integer id) {
		return this.empMapper.selectById(id);
	}

	/**
	 * 根据Id修改
	 */
	@Override
	public Integer updateEmpById(Emp bean, Integer id) {
		return this.empMapper.updateById(bean, id);
	}

	/**
	 * 根据Id删除
	 */
	@Override
	public Integer deleteEmpById(Integer id) {
		return this.empMapper.deleteById(id);
	}

	/**
	 * 根据Username获取对象
	 */
	@Override
	public Emp getEmpByUsername(String username) {
		return this.empMapper.selectByUsername(username);
	}

	/**
	 * 根据Username修改
	 */
	@Override
	public Integer updateEmpByUsername(Emp bean, String username) {
		return this.empMapper.updateByUsername(bean, username);
	}

	/**
	 * 根据Username删除
	 */
	@Override
	public Integer deleteEmpByUsername(String username) {
		return this.empMapper.deleteByUsername(username);
	}
}